﻿using System;
using System.Web.UI;


namespace mojoPortal.Web.RS.SBM
{
    public partial class RSLocationHistory2 : RSBasePage
    {
        int _callid = 0;
        int _companyid = 0;
        int _locationid = 0;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["callid"]))
                _callid = Convert.ToInt32(Request.QueryString["callid"].ToString());
            if (!String.IsNullOrEmpty(Request.QueryString["locationid"]))
                _locationid = Convert.ToInt32(Request.QueryString["locationid"].ToString());

            if (!Page.IsPostBack)
            {
                InitializeReadyServicePage("Location History");

                RSUserIdentity userIdentity = GetRSUserIdentity();
                _companyid = userIdentity.RSCompanyId;

                tcLocationHistory.Visible = false;
                if (_locationid > 0)
                {
                    hfSelectedLocationId.Value = _locationid.ToString();
                    ucLocationHeaderControl.LoadLocationHeader(_companyid, _locationid);
                    LoadLocationHistory(_companyid, _locationid);
                }

                if (Request.QueryString["tabindex"] != null)
                    tcLocationHistory.ActiveTabIndex = Convert.ToInt16(Request.QueryString["tabindex"].ToString());
                else
                    tcLocationHistory.ActiveTabIndex = 0;
            }
        }
        protected void lnkMapIt_Click(object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            int companyid = userIdentity.RSCompanyId; ;
            int locationid = ucLocationHeaderControl.LocationId;
            if (companyid > 0 && locationid > 0)
                ucModalViewMapControl.ShowMapDataByLocationID(companyid, locationid);
        }

        private void LoadLocationHistory(int companyid, int locationid)
        {
            tcLocationHistory.Visible = true;
            ucLocationContactListControl.LoadContactData(companyid, locationid);
            ucLocationAppointmentListControl.LoadAppointmentDataByID(companyid, locationid);
            tcLocationHistory.ActiveTab = tpLocationContact;
            hfSelectedLocationId.Value = locationid.ToString();
            ucCallListControl.LoadCallDataByLocationID(companyid, locationid);
            ucLocationInvoiceListControl.LoadInvoiceDataByLocationID(companyid, locationid);
            ucLocationEstimateListControl.LoadLocationEstimateListByID(companyid, locationid);
            ucLocationWorkOrderListControl.LoadLocationWorkOrderListByID(companyid, locationid);
        }

    }
}


